import { Link } from 'umi';
import { Badge, Space, Popconfirm  } from 'antd';
import {getBudgetCheckStatus, getBudgetSourceTypeName} from '@/utils/Common';

/* 首页tables */
export const indexColumns = function (delAction) {
  return [
    {
      title: '机构名称',
      key: 'unitName',
      dataIndex: 'unitName'
    },
    {
      title: '预算名称',
      key: 'code',
      dataIndex: 'code'
    },
    {
      title: '预算类型',
      key: 'numCategory',
      dataIndex: 'numCategory',
      align: 'center'
    },
    {
      title: '预算来源',
      key: 'sourceType',
      align: 'center',
      render: (text, record) => {
        return getBudgetSourceTypeName(record.sourceType) || '-'
      }
    },
    {
      title: '预算金额',
      key: 'amount',
      dataIndex: 'amount',
      align: 'center'
    },
    {
      title: '剩余金额',
      key: 'restAmount',
      dataIndex: 'restAmount',
      align: 'center'
    },
    {
      title: '创建时间',
      key: 'createTime',
      dataIndex: 'createTime',
      align: 'center'
    },
    {
      title: '操作',
      key: 'action',
      align: 'center',
      render: (_, row, index, action) => (
        <Space size="middle">
          <Link to={{ pathname: `/management/budget/detail`, query: { id: row.id } }}>详情</Link>
          <Link to={{ pathname: `/management/budget/modify`, query: { id: row.id } }}>修改</Link>
          <Popconfirm
            title="确定要删除此预算吗?"
            onConfirm={() => {delAction ? delAction(row.id) : null}}
            okText="确定"
            cancelText="取消">
            <a>删除</a>
          </Popconfirm >
        </Space>
      )
    },
  ];
} 


/* 详情页tables */
export const detailColumns = [
  {
    title: 'ISBN',
    key: 'isbn',
    dataIndex: 'isbn'
  },
  {
    title: '正题名',
    key: 'title',
    dataIndex: 'title',
    ellipsis: true
  },
  {
    title: '卷册号',
    key: 'volumeNo',
    dataIndex: 'volumeNo',
    align: 'center'
  },
  {
    title: '责任者',
    key: 'primaryAuthor',
    dataIndex: 'primaryAuthor',
    align: 'center'
  },
  {
    title: '预订类型',
    key: 'type',
    dataIndex: 'type',
    align: 'center'
  },
  {
    title: '原价',
    key: 'price',
    dataIndex: 'price',
    align: 'center'
  },
  {
    title: '状态',
    dataIndex: 'status',
    key: 'status',
    align: 'center',
    render: (status) => {
      const info = getBudgetCheckStatus(status)
      return <Badge status={info.badge} text={info.name} />
    }
  },
  {
    title: '介质类型',
    key: 'mediumType',
    dataIndex: 'mediumType',
    align: 'center'
  },
  {
    title: '预订册数',
    key: 'quantity',
    dataIndex: 'quantity',
    align: 'center'
  },
  {
    title: '预订价格',
    key: 'unitPrice',
    dataIndex: 'unitPrice',
    align: 'center'
  },
  {
    title: '创建时间',
    key: 'createTime',
    dataIndex: 'createTime',
    align: 'center',
    sorter: true
  }
];